package com.cl.edu.web;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.cl.core.orm.Page;
import com.cl.core.web.struts2.Struts2Utils;
import com.cl.edu.entity.Area;
import com.cl.edu.entity.Highschool;
import com.cl.edu.entity.Links;
import com.cl.edu.entity.News;
import com.cl.edu.entity.Teacher;
import com.cl.edu.entity.Status;
import com.cl.edu.entity.Student;
import com.cl.edu.entity.Subject;
import com.cl.edu.service.IndexManager;
import com.cl.edu.service.teacher.TeacherManager;
import com.cl.edu.service.RegisterManager;
import com.cl.edu.service.StudentManager;
import com.cl.edu.service.TeacherQueryManager;
import com.opensymphony.xwork2.ActionSupport;

@Results( { @Result(name = "teacher", location = "teacher/manage.action", type = "redirect") })
public class IndexAction extends ActionSupport{
	@Autowired
	private IndexManager indexManager;
	@Autowired
	private RegisterManager registerManager;
	@Autowired
	private TeacherQueryManager teacherQueryManager;
	@Autowired
	private StudentManager studentManager;
	@Autowired
	private TeacherManager teacherManager;

	private String username;
	private String password;
	private String yzm;
	 
	private Page<News> page = new Page<News>();
	
	private List<News> clwtsList;			//成龙网特色列表
	private List<News> cljjwList;			//成龙家教网列表
	private List<News> xxjyList;			//小学教育列表
	private List<News> czjyList;			//初中教育列表
	private List<News> gzjyList;			//高中教育列表
	private List<News> xxxxzyList;			//小学学习资源列表
	private List<News> czxxzyList;			//初中学习资源列表
	private List<News> gzxxzyList;			//高中学习资源列表
	private List<News> wykyList;			//外语口语列表
	private List<News> kyzxList;			//考研资讯列表
	private List<News> yslzxList;			//艺术类资讯列表
	
	//搜索模块
	private List<Area>  syList;//沈阳区划
	private List<Subject> subjectList;//学科列表
	private List<Subject> subjectList1;//简短学科列表
	private List<Status> statusList;//身份列表 所有
	private List<Status> statusList1;//身份列表 学生
	private List<Status> statusList2;//身份列表 教师
	private List<Status> statusList3;//身份列表 老外
	private List<Highschool> hxList;//高校列表 
	//教师及学生
	private List<Teacher> teaList; //专业教师列表
	private List<Teacher> starList;//星级家教
	private List<Teacher> uniList; //大学生教师列表
	private List<Student> stuList;//学生列表
	//private List<WeekStar> weekStar;//一周之星
	private List<Teacher> weekStar;//一周之星 
	
	private List<Links> linkList;
	
	public String execute() throws Exception {
		if (!page.isOrderBySetted()) {
			page.setOrderBy("time");
			page.setOrder(Page.DESC);
		}
		hxList        = registerManager.getHighschools();
		syList        = registerManager.getShenYang();
		statusList   = registerManager.getStatus(0l);
		statusList1   = registerManager.getStatus(1l);
		statusList2   = registerManager.getStatus(2l);
		statusList3   = registerManager.getStatus(3l);
		subjectList   = registerManager.getSubjects("2");
		subjectList1   = registerManager.getSubjects("1");
		Page<Teacher> page1=new Page<Teacher>();
		if (!page1.isOrderBySetted())		{
			page1.setOrderBy("id");
			page1.setOrder(Page.DESC);
		}
		page1.setPageSize(8);
		teaList=teacherQueryManager.getChoiceList(page1,2l).getResult();//专业教员列表获取
		page1.setPageSize(8);
		uniList=teacherQueryManager.getChoiceList(page1,1l).getResult();//大学生教员列表获取
		page1.setPageSize(10);
		if (!page1.isOrderBySetted())		{
			page1.setOrderBy("steptime");
			page1.setOrder(Page.DESC);
		}
		starList=teacherQueryManager.getChoiceList(page1).getResult();//星级教员
		
		//查询学生列表
		Page<Student> page2=new Page<Student>();
		if (!page2.isOrderBySetted()) {
			page2.setOrderBy("id");   
			page2.setOrder(Page.DESC);
		}
		page2.setPageSize(7);
		stuList=studentManager.getChoiceList(page2).getResult();
		
		// 成龙网特色 列表
		page = indexManager.getNewsById(page, 1L, 7);
		clwtsList = page.getResult();
		
		// 成龙家教网列表
		page = indexManager.getNewsById(page, 13L, 9);
		cljjwList = page.getResult();
		
		// 小学教育列表
		page = indexManager.getNewsById(page, 7L, 7);
		xxjyList = page.getResult();
		
		// 初中教育列表
		page = indexManager.getNewsById(page, 8L, 7);
		czjyList = page.getResult();
		
		
		// 高中教育列表
		page = indexManager.getNewsById(page, 9L, 7);
		gzjyList = page.getResult();
		
		
		// 小学学习资源列表
		page = indexManager.getNewsById(page, 4L, 5);
		xxxxzyList = page.getResult();
		
		
		// 初中学习资源列表
		page = indexManager.getNewsById(page, 5L, 5);
		czxxzyList = page.getResult();
		
		
		// 高中学习资源列表
		page = indexManager.getNewsById(page, 6L, 5);
		gzxxzyList = page.getResult();
		
		
		// 外语口语列表
		page = indexManager.getNewsById(page, 10L, 7);
		wykyList = page.getResult();
		
		// 考研资讯列表
		page = indexManager.getNewsById(page, 11L, 7);
		kyzxList = page.getResult();
		
		// 艺术类资讯列表
		page = indexManager.getNewsById(page, 12L, 7);
		yslzxList = page.getResult();

		//一周之星选择
//		Page<WeekStar> page3=new Page<WeekStar>();
//		if (!page3.isOrderBySetted()) {
//			page3.setOrderBy("id");   
//			page3.setOrder(Page.DESC);
//		}
		//weekStar=indexManager.getWeekStar(page3).getResult();
		weekStar = indexManager.getWeekStar(page1).getResult();
		
		linkList = indexManager.getLinkList();
		Struts2Utils.getSession().setAttribute("links", linkList);
		return SUCCESS;
	}
	
	
	public String login() throws Exception {
		
		if(!((String)Struts2Utils.getSession().getAttribute("rand")).equals(yzm)) {
			addActionMessage("验证码不正确");
			return execute();
		}
		
		Teacher teacher = new Teacher();
		teacher.setUsername(username);
		teacher.setPassword(password);
		if (teacherManager.hasUsername(teacher)) {
			teacher = teacherManager.isExist(teacher); 
			if (teacher != null) {
				if(teacher.getState() == 1) {	//状态为未审核则不1可登录 
					addActionMessage("您还没有通过验证，请尽快携带本人证件来成龙网办理认证!");
					return execute();
				} else {
					Struts2Utils.getSession().setAttribute("teacher", teacher);
					return "teacher";
				}
			} else {
				addActionMessage("密码不正确");
				return execute();
			}
		} else {
			addActionMessage("用户名不存在!");
			return execute();
		}
	}


	public Page<News> getPage() {
		return page;
	}


	public void setPage(Page<News> page) {
		this.page = page;
	}




	public List<News> getYslzxList() {
		return yslzxList;
	}


	public void setYslzxList(List<News> yslzxList) {
		this.yslzxList = yslzxList;
	}


	public String getUsername() {
		return username;
	}


	public void setUsername(String username) {
		this.username = username;
	}


	public String getPassword() {
		return password;
	}


	public void setPassword(String password) {
		this.password = password;
	}


	public String getYzm() {
		return yzm;
	}


	public void setYzm(String yzm) {
		this.yzm = yzm;
	}


	public List<Area> getSyList() {
		return syList;
	}


	public void setSyList(List<Area> syList) {
		this.syList = syList;
	}


	public List<Subject> getSubjectList() {
		return subjectList;
	}


	public void setSubjectList(List<Subject> subjectList) {
		this.subjectList = subjectList;
	}


	public List<Status> getStatusList() {
		return statusList;
	}


	public void setStatusList(List<Status> statusList) {
		this.statusList = statusList;
	}


	public List<Status> getStatusList1() {
		return statusList1;
	}


	public void setStatusList1(List<Status> statusList1) {
		this.statusList1 = statusList1;
	}


	public List<Status> getStatusList2() {
		return statusList2;
	}


	public void setStatusList2(List<Status> statusList2) {
		this.statusList2 = statusList2;
	}


	public List<Status> getStatusList3() {
		return statusList3;
	}


	public void setStatusList3(List<Status> statusList3) {
		this.statusList3 = statusList3;
	}


	public List<Highschool> getHxList() {
		return hxList;
	}


	public void setHxList(List<Highschool> hxList) {
		this.hxList = hxList;
	}


	public List<Teacher> getTeaList() {
		return teaList;
	}


	public void setTeaList(List<Teacher> teaList) {
		this.teaList = teaList;
	}


	public List<Teacher> getUniList() {
		return uniList;
	}


	public void setUniList(List<Teacher> uniList) {
		this.uniList = uniList;
	}


	public List<Student> getStuList() {
		return stuList;
	}


	public void setStuList(List<Student> stuList) {
		this.stuList = stuList;
	}


	public List<Teacher> getStarList() {
		return starList;
	}


	public void setStarList(List<Teacher> starList) {
		this.starList = starList;
	}


	public void setSubjectList1(List<Subject> subjectList1) {
		this.subjectList1 = subjectList1;
	}


	public IndexManager getIndexManager() {
		return indexManager;
	}


	public void setIndexManager(IndexManager indexManager) {
		this.indexManager = indexManager;
	}


	public RegisterManager getRegisterManager() {
		return registerManager;
	}


	public void setRegisterManager(RegisterManager registerManager) {
		this.registerManager = registerManager;
	}


	public TeacherQueryManager getTeacherQueryManager() {
		return teacherQueryManager;
	}


	public void setTeacherQueryManager(TeacherQueryManager teacherQueryManager) {
		this.teacherQueryManager = teacherQueryManager;
	}


	public StudentManager getStudentManager() {
		return studentManager;
	}


	public void setStudentManager(StudentManager studentManager) {
		this.studentManager = studentManager;
	}


	public TeacherManager getTeacherManager() {
		return teacherManager;
	}


	public void setTeacherManager(TeacherManager teacherManager) {
		this.teacherManager = teacherManager;
	}


	public List<News> getClwtsList() {
		return clwtsList;
	}


	public void setClwtsList(List<News> clwtsList) {
		this.clwtsList = clwtsList;
	}


	public List<News> getCljjwList() {
		return cljjwList;
	}


	public void setCljjwList(List<News> cljjwList) {
		this.cljjwList = cljjwList;
	}


	public List<News> getXxjyList() {
		return xxjyList;
	}


	public void setXxjyList(List<News> xxjyList) {
		this.xxjyList = xxjyList;
	}


	public List<News> getCzjyList() {
		return czjyList;
	}


	public void setCzjyList(List<News> czjyList) {
		this.czjyList = czjyList;
	}


	public List<News> getGzjyList() {
		return gzjyList;
	}


	public void setGzjyList(List<News> gzjyList) {
		this.gzjyList = gzjyList;
	}


	public List<News> getXxxxzyList() {
		return xxxxzyList;
	}


	public void setXxxxzyList(List<News> xxxxzyList) {
		this.xxxxzyList = xxxxzyList;
	}


	public List<News> getCzxxzyList() {
		return czxxzyList;
	}


	public void setCzxxzyList(List<News> czxxzyList) {
		this.czxxzyList = czxxzyList;
	}


	public List<News> getGzxxzyList() {
		return gzxxzyList;
	}


	public void setGzxxzyList(List<News> gzxxzyList) {
		this.gzxxzyList = gzxxzyList;
	}


	public List<News> getWykyList() {
		return wykyList;
	}


	public void setWykyList(List<News> wykyList) {
		this.wykyList = wykyList;
	}


	public List<News> getKyzxList() {
		return kyzxList;
	}


	public void setKyzxList(List<News> kyzxList) {
		this.kyzxList = kyzxList;
	}


	public List<Subject> getSubjectList1() {
		return subjectList1;
	}


	public List<Teacher> getWeekStar() {
		return weekStar;
	}


	public void setWeekStar(List<Teacher> weekStar) {
		this.weekStar = weekStar;
	}


	public List<Links> getLinkList() {
		return linkList;
	}


	public void setLinkList(List<Links> linkList) {
		this.linkList = linkList;
	}


//	public void setWeekStar(List<WeekStar> weekStar) {
//		this.weekStar = weekStar;
//	}
//
//
//	public List<WeekStar> getWeekStar() {
//		return weekStar;
//	}
	
}
